package com.fuyao.cloud.asset.inventory.process;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fuyao.cloud.asset.card.service.AssetAssetcardService;
import com.fuyao.cloud.asset.card.wrappers.CardWrappersUtil;
import com.fuyao.cloud.asset.entity.AssetCard;
import com.fuyao.cloud.asset.inventory.entity.InventoryTask;
import com.fuyao.cloud.asset.inventory.enums.InventoryTaskTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author lyhills
 * @Description
 * @date 2023/9/15 16:30
 * @Version 1.0
 */
@Slf4j
@Service
@InventoryTaskType(value = "unit")
public class InventoryUseDeptAssetCard implements InventoryTaskTypeFactory {

    @Resource
    private AssetAssetcardService assetAssetcardService;

    @Override
    public String getType() {
        return InventoryTaskTypeEnum.UNIT.getCode();
    }

    @Override
    public List<AssetCard> getAssetCardList(InventoryTask entity) {
        Assert.isTrue(StrUtil.isNotEmpty(entity.getTypeIds()),String.format(" inventoryTask：id [%s], typeIds is null ",entity.getId()));

        LambdaQueryWrapper<AssetCard> assetCardFilterStatusWrapper = CardWrappersUtil.getAssetCardFilterStatusWrapper();
        assetCardFilterStatusWrapper.in(StrUtil.isNotBlank(entity.getAssetStatus()), AssetCard::getStatus, StrUtil.split(entity.getAssetStatus(), ","));
        assetCardFilterStatusWrapper.in(AssetCard::getUsedeptId, StrUtil.split(entity.getTypeIds(), ","));

        List<AssetCard> list = assetAssetcardService.list(assetCardFilterStatusWrapper);
        log.info(StrUtil.format("单位类型共找出资产数据共{0}条",list.size()));
        return list;
    }
}
